package com.lvhx.springboot.callservice;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public class DefaultServiceProvider implements IServiceProvider, ApplicationContextAware {

    private ApplicationContext appContext;
    @Override
    public <T> T getService(Class<T> serviceTyp) {
        return (T) appContext.getBean(serviceTyp.getSimpleName());
    }

    @Override
    public Object getService(String serviceNmae) {
        return appContext.getBean(serviceNmae);
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        appContext = applicationContext;
    }
}
